<template>
  <a-card :bordered="false" class="card-area">
    <div class="table-page-search-wrapper">
      <a-form layout="vertical">
        <a-row :gutter="48">
          <a-col :md="6" :sm="12">
            <a-form-item label="学号">
              <a-input v-model="queryParam.xh"/>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="12">
            <a-form-item label="姓名">
              <a-input v-model="queryParam.xm"/>
            </a-form-item>
          </a-col>
          <template v-if="advanced">
            <a-col :md="6" :sm="12">
              <a-form-item label="院系">
                <a-select :disabled="selectMenu.yx.length===1" allowClear v-model="queryParam.ssyxm" @change="yxChange" showSearch :filterOption="filterOption">
                  <a-select-option v-for="i in selectMenu.yx" :key="i.id" :value="i.dwh">{{ i.dwh }} {{ i.dwmc }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="12">
              <a-form-item label="专业">
                <a-select allowClear v-model="queryParam.sszym" showSearch :filterOption="filterOption">
                  <a-select-option v-for="i in selectMenu.zy" :key="i.id" :value="i.zyh">{{ i.zyh}} {{ i.zymc }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="12">
            <a-form-item
              label="出发地"
            >
              <a-input v-model="queryParam.cfd"/>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="12">
            <a-form-item
              label="目的地"
            >
              <a-input v-model="queryParam.mdd"/>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="12">
            <a-form-item
              label="出发时间"
            >
              <a-date-picker v-model="postParams.cfsj"/>
            </a-form-item>
          </a-col>
          </template>
          <a-col :md="10" :sm="20">
            <span class="table-page-search-submitButtons" >
              <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
              <!-- <a-button type="primary" @click="batchCheck">批量审核</a-button> -->
              <!-- <a-button type="primary">导出</a-button> -->
              <a-button @click="downloadStencil" type="primary">导出</a-button>

              <a-button style="margin-left: 8px" @click="() =>  queryParam = {ssyxm: selectMenu.yx.length === 1 ? queryParam.ssyxm : ''}">重置</a-button>
              <a @click="advanced = !advanced" style="margin-left: 8px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
      <s-table
        ref="table"
        size="default"
        rowKey="id"
        :columns="columns"
        :data="loadData"
        :alert="options.alert"
        :rowSelection="options.rowSelection"
        :pageSize="pageSize"
        :scroll="{x: 1200}"
      >
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 }}
        </span>
       <template slot="operation" slot-scope="a,b">
          <a v-hasPermission="'cfxxsb:update'" @click="edit(b)">修改</a>
       </template>

      </s-table>
      <infor-modal
      ref="check"
      :visible="visible"
      :info ='rptInfo'
      @cancel="cancelThis"
      @refresh="$refs.table.refresh(true)"
    />
    </div>
  </a-card>
  
</template>

<script>
  // import moment from 'moment'
  import {STable} from '~'
  import {mapState} from 'vuex'
  import inforModal from './inforModal'

  export default {
  name: 'TableList',
  components: {
    STable,inforModal
  },
  data () {
    return {
      // 高级搜索 展开/关闭
      advanced: true,
      // 查询参数
      queryParam: {},
      postParams:{},
      // 表头
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: '学号',
          dataIndex: 'xh'
        },
        {
          title: '姓名',
          dataIndex: 'xm'
        },
        {
          title: '院系',
          dataIndex: 'ssyxmc'
        },
        {
          title: '专业',
          dataIndex: 'sszymc'
        },
        {
          title: '联系方式',
          dataIndex: 'lxdh'
        },
        {
          title: '出发时间',
          dataIndex: 'cfsj' 
        },
        {
          title: '出发地',
          dataIndex: 'cfd'
        },
        {
          title: '目的地',
          dataIndex: 'mdd'
        },
        // {
        //   title: '审核状态',
        //   dataIndex: 'shzt'
        // },
        {
          title: '操作',
          scopedSlots: { customRender: 'operation' },
          width:100,
          fixed:'right'
        }
      ],
      shzt:"",
      pageSize: 10,
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        if (this.pageSize !== 10) {
          parameter.pageSize = this.pageSize
        } else {
          this.pageSize = parameter.pageSize
        }
        parameter.pageNum = parameter.pageNo
        let params = Object.assign(this.queryParam, parameter)
        if(this.postParams.cfsj){
            params.cfsj = this.postParams.cfsj.format('YYYY-MM-DD');
        }else {
            delete params.cfsj
        }
        return this.$api.student.gjhxmsbList(params).then(res => {
          return {
            data: res.data.rows ? res.data.rows : [],
            pageNo: parameter.pageNo,
            pageSize: parameter.pageSize,
            totalPage: Math.ceil(res.data.total / parameter.pageSize),
            totalCount: res.data.total
          }
        })
      },
      selectedRowKeys: [],
      selectedRows: [],
      options: {
        alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
        rowSelection: {
          selectedRowKeys: this.selectedRowKeys,
          onChange: this.onSelectChange
        }
      },
      selectMenu: {
        yx: [],
        zy: []
      },
      visible: false,
      rptInfo:{},
    }
  },
  computed: {
    ...mapState({
      TYPE0125: state => state.app['TYPE0125'],
      TYPE0075: state => state.app['TYPE0075'],
      TYPE0503: state => state.app['TYPE0503'],
      TYPE0126: state => state.app['TYPE0126'],
      TYPE0455: state => state.app['TYPE0455'],
    })
  },
  beforeCreate () {
    this.form = this.$form.createForm(this)
  },
  created () {
    this.initSelectMenu()
    this.$store.dispatch('app/setDictionary', 'TYPE0075')
    this.$store.dispatch('app/setDictionary', 'TYPE0126')
    this.$store.dispatch('app/setDictionary', 'TYPE0125')
    this.$store.dispatch('app/setDictionary', 'TYPE0503')
    this.$store.dispatch('app/setDictionary', 'TYPE0455')
    this.$store.dispatch('app/sysInfo').then(data => {
      this.$nextTick(() => {
        this.$refs.table.refresh()
      })
    })
  },
  methods: {
    initSelectMenu () {
      
      let allRequest = [
        this.$api.base.collegeAll(),
        this.$api.student.yxSchoolSubmitDate(),
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yx: res[0].data,
          time: res[1].data
        }
        if(this.selectMenu.yx && this.selectMenu.yx.length == 1){
          this.$set(this.queryParam, 'ssyxm', this.selectMenu.yx[0].dwh)
          this.yxChange(this.queryParam.ssyxm)
        }
        this.$nextTick(() => {
          this.$refs.table.refresh(true)
        })
      })
    },
    changeTime(data,str){
      console.log(str)
      this.queryParam.submitDate = str
      
    },
    filterOption (value, op) {
      return op.componentOptions.children[0].text.indexOf(value) !== -1
    },
    onSelectChange (selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    yxChange (code) {
      this.$set(this.queryParam, 'sszym', '')
      this.$api.base.majorAll({lsdwh: code}).then(res => {
        this.$set(this.selectMenu, 'zy', res.data)
      })
    },
    edit(info){
      this.visible = true
      this.rptInfo = JSON.parse(JSON.stringify(info)) 
    },
    cancelThis(){
        this.visible = false;
        this.$refs.check.form.resetFields()
        this.rptInfo = {}
    },
    downloadStencil(){
      this.$export('/admissions/GjhCfsb/export', {
        ...this.queryParam
      })
    },
  }
}
</script>
